const app = getApp()

import {formatTime} from '../../utils/util'

Page({
    data: {
        userInfo: {},
        historyList: [],
        statusMap: {
            0: '失败',
            1: '完成'
        }
    },
    onLoad() {
		app.userstat(this,wx.getStorageSync("openid"));
		
		this.getTestHistory()
		this.setData({
		    userInfo: app.userInfo
		})
    },
    transformData(data) {
        return data.map(e => {
            e.update_time = formatTime(new Date(parseInt(e.update_time + '000')))
            e.status_text = this.data.statusMap[e.status]
            return e
        })
    },
    getTestHistory() {
        app.request(app.apiDomain + 'index.php?c=face&a=faceuserlist', {
            page: 1,
            size: 30,
        }, (res) => {
            console.log(res);
            
            this.setData({
                historyList: this.transformData(res.data.data.list) || []
            })
        })
    },
    goToPage(e) {
        let orderId = e.currentTarget.dataset.id
        let status = e.currentTarget.dataset.status
        if (status == '1') {
            wx.navigateTo({
                url: `result?orderId=${orderId}`
            })
        } else {
            wx.navigateTo({
                url: `index?orderId=${orderId}`
            })
        }
    },
    goToFirstPage() {
        wx.navigateTo({
            url: 'index'
        })
    },
    onShareAppMessage() {
        return {
        	path: '/pages/skin/index',
        	title: '我的AI皮肤健康报告出来啦~,你也来试试？'
        }
    }
})
